all: system
	objcopy -I elf64-x86-64 -S -R ".eh_frame" -R ".comment" -O binary system kernel.bin

system:	head.o entry.o main.o printk.o trap.o memory.o
	ld -b elf64-x86-64 -z muldefs -o system head.o entry.o main.o printk.o trap.o memory.o -T Kernel.lds 

head.o:	head.S
	gcc -E  head.S > head.s
	as --64 -o head.o head.s

entry.o: entry.S
	gcc -E  entry.S > entry.s
	as --64 -o entry.o entry.s
	
main.o:	main.c
	gcc  -fno-stack-protector -mcmodel=large -fno-builtin -m64 -c main.c
	
printk.o: printk.c
	gcc  -fno-stack-protector -mcmodel=large -fno-builtin -m64 -c printk.c

trap.o: trap.c
	gcc  -fno-stack-protector -mcmodel=large -fno-builtin -m64 -c trap.c

memory.o: memory.c
	gcc  -fno-stack-protector -mcmodel=large -fno-builtin -m64 -c memory.c

clean:
	rm -rf *.o *.s~ *.s *.S~ *.c~ *.h~ system  Makefile~ Kernel.lds~ kernel.bin 

